/**
 * Created by chenzui on 2017/5/25.
 */
function getURLParameter(name) {
    return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [null, ''])[1].replace(/\+/g, '%20')) || null;
}

var oId = getURLParameter('oId');

function callBackForPay(type,status) {
    if(status === 1){
        //支付成功
        location.href = 'order.html?oId=' + oId;
    }else {
        
    }
}
function callBackForLogin(openId) {
    alert("openId:"+openId);
    $.ajax(
        getAjaxOps('/user/login', {openId:openId})
    ).done(function(res){
        alert("ajax res:"+res);
        if(res.resultCode == 0){
            setUser(res.data.userId, new Date().getTime());
            clearPreUrl();
            location.replace(PRE_URL);
        }
    });
}
//微信统一下单接口
function wxUnifiedorder() {
    $.ajax({
        // url: 'http://127.0.0.1:8080/wxinpay/unifiedorder',
        url: 'http://120.77.86.178:41000/wxinpay/unifiedorder',
        data: {orderId: oId},
        type: 'POST',
        dataType: 'json'
    }).done(function (res) {
        var payInfo = res.data;
        // public void wxpay(String prepayId,String nonceStr,String paySign,String time)
        // alert("准备调用安卓原生支付"+"prepay_id:"+payInfo.prepay_id+"------nonce_str:"+payInfo.nonce_str+"------sign:"+payInfo.sign+"==------timeStamp:"+payInfo.timeStamp);

        window.frontshoes.wxpay(payInfo.prepay_id.toString(),payInfo.nonce_str.toString(),payInfo.sign.toString(),payInfo.timeStamp.toString());
    });
}
$(function () {
    $(".payitem").on("click",function(){
        $(".payitem .icon-rightselect").removeClass("cur");
        $(this).find(".icon-rightselect").toggleClass("cur");
    });

    $.ajax({
        url: 'http://120.77.86.178:41000/order/qryOrderDetail',
        data: {orderId: oId},
        type: 'POST',
        dataType: 'json'
    }).done(function (res) {
        if(res.resultCode == 0){
            console.log("........");
            $('#price').html('&yen;'+parseFloat(res.data.orderFee).toFixed(2));
            $('#pay').on('click', function(){
                var type = $('.payitem .cur').eq(0).attr("data-type");
                if(type == "2"){
                    window.frontshoes.alipay(res.data.orderNbr.toString(),res.data.orderFee.toString());
                }else {

                    // alert("调起统一支付");
                    wxUnifiedorder();
                }

            });
        }else{
            alert(res.resultMsg);
        }
    });
})